#include<algorithm>
#include<cstdio>
#include<cstring>
#define eps 1e-6
#define INF 0x3f3f3f3f
#define inf 1e18
#define ll long long
#define db double
#define pb push_back
#define mk make_pair
inline int read(){
    char ch=getchar();
    int x=0,f=1;
    while(ch<'0'||ch>'9'){
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
using namespace std;
#define M 100005
int n,m,L,lim,det[M];
struct vehicle{
    int x0,v0,a;
}veh[M];
struct restr{
    int l,r;
    friend bool operator<(restr a,restr b){
        return a.r==b.r?a.l<b.l:a.r<b.r;
    }
}rst[M];
ll sq(int x){return 1ll*x*x;}
ll div_up(ll x,ll y){return (x+y-1)/y;}
int find(ll pos){
    int l=1,r=m,res=-1;
    while(l<=r){
        int mid=(l+r)>>1;
        if(det[mid]<=pos) res=mid,l=mid+1;
        else r=mid-1;
    }
    return res;
}
void solve(){
    n=read(),m=read(),L=read(),lim=read();
    for(int i=1;i<=n;i++){
        veh[i].x0=read();
        veh[i].v0=read();
        veh[i].a=read();
    }
    for(int i=1;i<=m;i++) det[i]=read();
    int ans1=0,ans2=m,tot=0;
    for(int i=1;i<=n;i++){
        vehicle cur=veh[i];
        if(cur.a>0){
            ll lpos=cur.v0>lim?cur.x0:(sq(lim)-sq(cur.v0)+2ll*cur.a*cur.x0)/(2*cur.a)+1;
            if(det[m]<lpos) continue;
            ans1++;rst[++tot]={int(lower_bound(det+1,det+m+1,lpos)-det),m};
        }else if(cur.a==0){
            int pos=lower_bound(det+1,det+m+1,cur.x0)-det;
            if(cur.v0<=lim||pos==m+1) continue;
            ans1++;rst[++tot]={pos,m};
        }else{
            int pos=lower_bound(det+1,det+m+1,cur.x0)-det;
            if(cur.v0<=lim||pos==m+1) continue;
            ll lpos=div_up(-sq(lim)+sq(cur.v0)-2ll*cur.a*cur.x0,-2*cur.a)-1;
            if(lpos<det[pos]) continue;
            ans1++;rst[++tot]={pos,find(lpos)};
        }
    }
    sort(rst+1,rst+tot+1);
    int lst=0;
    for(int i=1;i<=tot;i++){
        if(lst<rst[i].l) ans2--,lst=rst[i].r; 
    }
    printf("%d %d\n",ans1,ans2);
}
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int T=read();
    while(T--) solve();
    return 0;
}